from app.storage.storage_flow.model import StorageFlow as StorageFlowTable
from app.storage.storage_flow import dao
from common.mixins import DictMixin
from common.utils.utils import custom_marshal_pagination
from exts import db


# ------------- route ------------
def create(user_id, **kwargs):
    new_obj = DictMixin.from_dict(StorageFlowTable, kwargs)
    new_obj.creator_id = user_id
    db.session.add(new_obj)
    db.session.commit()
    return new_obj


def get_by_page(user_id, **kwargs):
    pagination = dao.get_by_page(**kwargs)
    pagination = custom_marshal_pagination(pagination)
    return pagination


def get(user_id, obj_id):
    return StorageFlowTable.query.filter_by(id=obj_id).first()



